package com.hnichr.ump.plan.controller;

import com.hnichr.ump.common.plan.entity.PlanGroup;
import com.hnichr.ump.common.plan.service.PlanGroupService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/plan/group/v1/")
@Tag(name = "PlanGroupController", description = "重点工作角色组接口")
public class PlanGroupController {

    @Autowired
    private PlanGroupService planGroupService;

    @GetMapping("list")
    @Operation(summary = "重点工作角色组列表", description = "获取重点工作角色组（无分页）", method = "GET")
    public Result<List<PlanGroup>> list(@Parameter(description="查询参数") Criteria criteria){
        List<PlanGroup> list = planGroupService.list(PlanGroup.class,criteria);
        return Result.OK(list);
    }

    @GetMapping("page")
    @Operation(summary = "重点工作角色组列表", description = "重点重点工作角色组（分页）", method = "GET")
    public Result<Page<PlanGroup>> page(@Parameter(description="查询参数")  Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo){
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<PlanGroup> list = planGroupService.listPage(PlanGroup.class,page, criteria);
        return Result.OK(list);
    }
}
